(function (vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addHousekeepingServUserInfo: {
                servUserId: '',
                staffId: '',
                staffName: '',
                state: '',
                remark: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addHousekeepingServUser', 'openAddHousekeepingServUserModal', function () {
                $('#addHousekeepingServUserModel').modal('show');
            });
        },
        methods: {
            addHousekeepingServUserValidate() {
                return vc.validate.validate({
                    addHousekeepingServUserInfo: $that.addHousekeepingServUserInfo
                }, {
                    'addHousekeepingServUserInfo.staffId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "员工ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "员工ID太长"
                        },
                    ],
                    'addHousekeepingServUserInfo.staffName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "员工名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "员工名称太长"
                        },
                    ],
                    'addHousekeepingServUserInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "员工状态不能为空"
                        }
                    ],
                        'addHousekeepingServUserInfo.remark': [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "描述，一般为状态变更描述不能为空"
                            },
                            {
                                limit: "maxLength",
                                param: "120",
                                errInfo: "描述太长"
                            },
                        ],




                });
            },
            saveHousekeepingServUserInfo: function () {
                if (!$that.addHousekeepingServUserValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }

                $that.addHousekeepingServUserInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addHousekeepingServUserInfo);
                    $('#addHousekeepingServUserModel').modal('hide');
                    return;
                }

                vc.http.apiPost(
                    '/housekeepingServUser/saveHousekeepingServUser',
                    JSON.stringify($that.addHousekeepingServUserInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addHousekeepingServUserModel').modal('hide');
                            $that.clearAddHousekeepingServUserInfo();
                            vc.emit('housekeepingServUserManage', 'listHousekeepingServUser', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddHousekeepingServUserInfo: function () {
                $that.addHousekeepingServUserInfo = {
                    staffId: '',
                    staffName: '',
                    state: '',
                    remark: '',

                };
            }
        }
    });

})(window.vc);
